import { makeAutoObservable } from 'mobx'
import type { SceneItem } from './interface'
import { getSceneList } from './api'
import SceneIcon1 from '@/resource/scene/level_1.png'
import SceneIcon2 from '@/resource/scene/level_2.png'
import SceneIcon3 from '@/resource/scene/level_3.png'
import SceneIcon4 from '@/resource/scene/level_4.png'
import { getLocalStorage, setLocalStorage } from '@/storage'
import dayjs from 'dayjs'
import { getData, postData, putData } from '@/servers/http'
import { api } from '@/servers/api'

class Store {
    sceneList: SceneItem[] | [] = []
    sceneIconList = [SceneIcon2, SceneIcon3, SceneIcon1, SceneIcon4]
    step: number = 0
    welcomeVisible: boolean = false
    userInfo: any = {}

    constructor() {
        makeAutoObservable(this)
        this.getUserInfo()
    }

    async getSceneListData() {
        const { data } = await getSceneList()
        this.sceneList = data?.reverse()
        console.log('this.step', this.step, getLocalStorage('GUIDE'))

        if (String(this.userInfo.is_guide_operation) === '0') {
            this.welcomeVisible = true
            setLocalStorage('GUIDE_DATE', dayjs().format('YYYY-MM-DD'))
            setLocalStorage('GUIDE', '0')
        }
    }

    nextStep = () => {
        this.step = this.step + 1
    }

    closeModal = () => {
        this.welcomeVisible = false
        this.isFinish()
        this.step = 1
    }

    getUserInfo = () => {
        getData(api.usersLoginUserInfo).then(res => {
            this.userInfo = res.data
            this.getSceneListData()
        })
    }

    isFinish = () => {
        putData(api.usersFinishGuide)
    }
}
export default Store
